package com.epsi.mightymaps.act;

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.epsi.mightymaps.R;
import com.epsi.mightymaps.hdl.EnableEditTextOnCheckedChangeAction;
import com.epsi.mightymaps.hdl.SendCourseAction;

public class SendCourseActivity extends Activity {
	TextView titleTextView, descriptionTextView;
	CheckBox passwordCheckBox;
	EditText passwordEditText, titleEditText, descriptionEditText;
	LinearLayout layout;
	Button sendButton;
	File courseFile;

	// public SendCourseActivity(File courseFile) {
	// this.courseFile = courseFile;
	// }

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initField();
		setActionListener();
		designLayout();
		setContentView(layout);
	}

	private void designLayout() {
		// layout add view
		layout.addView(titleTextView);
		layout.addView(titleEditText);
		layout.addView(descriptionTextView);
		layout.addView(descriptionEditText);
		layout.addView(passwordCheckBox);
		layout.addView(passwordEditText);
		layout.addView(sendButton);
	}

	private void setActionListener() {
		// set listener
		passwordCheckBox
				.setOnCheckedChangeListener(new EnableEditTextOnCheckedChangeAction(
						passwordEditText));

		sendButton.setOnClickListener(new SendCourseAction(this));
	}

	private void initField() {
		// Init layout
		layout = new LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL);

		// init field
		titleTextView = new TextView(layout.getContext());
		titleTextView.setText(R.string.title);

		titleEditText = new EditText(layout.getContext());

		descriptionTextView = new TextView(this);
		descriptionTextView.setText(R.string.description);

		descriptionEditText = new EditText(this);
		descriptionEditText.setLines(3);

		passwordCheckBox = new CheckBox(this);
		passwordCheckBox.setText(R.string.password);

		passwordEditText = new EditText(this);
		passwordEditText
				.setTransformationMethod(new PasswordTransformationMethod());
		passwordEditText.setEnabled(false);

		sendButton = new Button(this);
		sendButton.setText(R.string.send);
	}

	public CheckBox getPasswordCheckBox() {
		return passwordCheckBox;
	}

	public String getPassword() {
		return passwordEditText.getText().toString();
	}

	public String getCourseTitle() {
		return titleEditText.getText().toString();
	}

	public String getDescription() {
		return descriptionEditText.getText().toString();
	}

	public File getCourseFile() {
		return courseFile;
	}

}